﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using RS.Tool.Init;
using System.Web;

namespace BaseAuthRole.Web.Filters
{
    public class PageAuthCheckFilter: ActionFilterAttribute
    { //action执行后
        public override void OnActionExecuted(ActionExecutedContext context)
        {
            
        }
        //action执行前
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            var return_url ="http"+$"{(context.HttpContext.Request.IsHttps?"s":"")}"+"://" +context.HttpContext.Request.Host + context.HttpContext.Request.Path + context.HttpContext.Request.QueryString;

            var arguments = context.ActionArguments;

            var method = context.HttpContext.Request.Method;

            //通过cookie检查有效性 uid 及token 有效性

            var userloginInfo = UserCookieHelper.GetCookieUserInfo();

            if (userloginInfo == null) {
               
                   var url = $"{@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")}/Home/Login?return_url={HttpUtility.UrlEncode(return_url)}";

                   context.Result = new RedirectResult(url);

            }
            else
            {



            }
        }

    }
}
